package com.jingyuan.biz.manager;

import com.google.common.collect.Maps;
import io.netty.channel.Channel;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 管理与客户端的连接。貌似不需要了
 */
@Service
public class ClientChannelManager {
    private Map<String,Channel> clientChannelMap=new ConcurrentHashMap<>();

    public void addChannel(String address,Channel channel){
        clientChannelMap.put(address,channel);
    }

    public Channel getChannel(String address){
        return clientChannelMap.getOrDefault(address,null);
    }

    public Map<String,Channel> getClientChannelMap(){
        return Maps.newHashMap(clientChannelMap);   //返回复制，todo 防止线程并发异常，是否需要这样有待考证
    }
}
